<?php
/**
 * 系统用户逻辑模型
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/10/9 0009
 * Time: 16:11
 */
namespace app\admin\logic;
use app\admin\model\SystemAuth;
use service\LogService;
use service\NodeService;
use think\Db;
use think\Model;
use app\admin\model\SystemUser;

class SystemUserBll extends Model{

    /**
     * 登录后逻辑处理
     * @param string $username 用户名（账号）
     */
    public static function loginSuccLogic($username){
        $user = SystemUser::where('username',$username)->find();
        // 更新登录信息
        $data = [
            'login_at' => Db::raw('now()'),
            'login_num' => Db::raw('login_num+1')
        ];
        Db::name('system_user')->where('id',$user['id'])->update($data);
        session('user', $user);
        !empty($user['authorize']) && NodeService::applyAuthNode();
        LogService::write('系统管理', '用户登录系统成功');
        return rstReturn(true);
    }
}